﻿using System;
using Microsoft.Xna.Framework;

namespace TD.Interface.Controls
{
    /// <summary>
    /// A button from the main menu.
    /// </summary>
    internal class ButtonMain : ButtonBase
    {
        protected const int OFFSET_HOVER = 8;
        protected const int OFFSET_X_TEXT = 32;
        protected const int OFFSET_Y_TEXT = 24;
        protected const int OFFSET_X_SUB_TEXT = OFFSET_X_TEXT;
        protected const int OFFSET_Y_SUB_TEXT = (OFFSET_Y_TEXT + 50);

        /// <summary>
        /// A restore point for the main menu animation.
        /// </summary>
        public Point Restore { get; set; }

        private new Vector2 textCoord;
        private new Vector2? subTextCoord;

        public ButtonMain(Game1 game, string assetName, Point point, string text, Vector2 textCoord, string subText = "", Vector2? subTextCoord = null) :
            base(game, assetName, point, text, textCoord, subText, subTextCoord)
        {
            this.textCoord = new Vector2(textCoord.X + OFFSET_X_TEXT, textCoord.Y + OFFSET_Y_TEXT);
            if (subTextCoord.HasValue)
            {
                this.subTextCoord = new Vector2(subTextCoord.Value.X + OFFSET_X_SUB_TEXT, subTextCoord.Value.Y + OFFSET_Y_SUB_TEXT);
            }
            else
            {
                this.subTextCoord = null;
            }
            this.Restore = point;
        }

        protected override void Modifiers(GameTime gameTime)
        {
            if (HasFocus)
            {
                base.textCoord = new Vector2(this.textCoord.X + OFFSET_HOVER, this.textCoord.Y);
                if (this.subTextCoord.HasValue)
                {
                    base.subTextCoord = new Vector2(this.subTextCoord.Value.X + OFFSET_HOVER, this.subTextCoord.Value.Y);
                }
            }
            else
            {
                base.textCoord = textCoord;
                if (this.subTextCoord.HasValue)
                {
                    base.subTextCoord = this.subTextCoord;
                }
            }
        }
    }
}
